package com.yqy.controller;

import com.yqy.config.ResponseData;
import com.yqy.entity.UserDTO;
import com.yqy.entity.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2023/7/11 15:26
 * @updateUser : modify
 * @updateTime : 2023/7/11 15:26
 * @updateRemark :
 */
@Api(tags = "人员相关接口")
@RestController
public class UserController {

    private final static Integer MAX_PAGE_SIZE = 2000;

    @PostMapping("/find/user/page")
    @ApiOperation(value = "分页查询用户", notes = "")
    public ResponseData<UserVO> findUser(@RequestParam @ApiParam(name = "pageNo", value = "当前页", required = true, example = "1") Integer pageNo,
                                         @RequestParam @ApiParam(name = "pageSize", value = "每页条数", required = true, example = "50") @Max(value = 2000, message = "每页条数不能超过2000") Integer pageSize,
                                         @Validated @RequestBody UserDTO userDTO) throws Exception {
        if (pageSize > MAX_PAGE_SIZE) {
            throw new Exception("每页条数不能超过2000");
        }
        return ResponseData.ok(new UserVO());
    }

    @PostMapping("/user/insert")
    @ApiOperation(value = "新增用户", notes = "")
    public ResponseData<Integer> insert(@Validated @RequestBody UserDTO userDTO) {

        return ResponseData.ok(1);
    }

    @PostMapping("/user/update")
    @ApiOperation(value = "修改用户信息", notes = "")
    public ResponseData<Integer> update(@Validated @RequestBody UserDTO userDTO) throws Exception {
        UserVO userVO = new UserVO();
        if (userDTO.getName().equals(userVO.getName())) {
            throw new Exception("姓名不能修改");
        }
        return ResponseData.ok(1);
    }
}
